import { UserSearchRoots, UserHiddenRoots } from '@entity/user';
import { Axios } from '@axios/base'
import { HttpStatus } from '@axios/base/http_status';

export class UserRoots extends Axios {

    constructor() {
        super('user/roots');
    }

    /**
     * POST /user/roots/hidden
     * 更新用户的隐藏权限
     * @param data 隐藏权限
     */
    async updateHidden(data: UserHiddenRoots): Promise<Boolean> {
        const result = await this.post<Boolean>('/hidden', data);
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

    /**
     * GET /user/roots/hidden
     * 获取指定 id 用户的隐藏权限
     * @param id 用户 id
     */
    async queryHidden(id: number): Promise<UserHiddenRoots> {
        const result = await this.get<UserHiddenRoots>('/hidden', {
            params: {
                targetId: id,
            }
        });
        return result.status == HttpStatus.SUCCESS ? result.data : new UserHiddenRoots();
    }

    /**
     * POST /user/roots/search
     * 更新用户的被搜索权限
     * @param data 被搜索权限
     */
    async updateSearch(data: UserSearchRoots): Promise<Boolean> {
        const result = await this.post<Boolean>('/search', data);
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

    /**
     * GET /user/roots/search
     * 获取指定 id 用户的被搜索权限
     * @param data 被搜索权限
     */
    async querySearch(id: number): Promise<UserSearchRoots> {
        const result = await this.get<UserSearchRoots>('/search', {
            params: {
                targetId: id,
            }
        });
        return result.status == HttpStatus.SUCCESS ? result.data : new UserSearchRoots();
    }

}